{extend name="common/base" /} {block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">管理员列表</div>
                        <div class="layui-card-body admin-table">
                            <div class="layui-row admin-table-action">
                                <div class="layui-col-md6 tool-action">
                                    <a data-href="{:url('/admin/user/admin/add')}" data-title="新增管理员" admin-event="formLayer" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary">
                                        <i class="layui-icon layui-icon-add-circle"></i>
                                    </a>
                                    <button id="layui-icon-refresh" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary">
                                        <i class="layui-icon layui-icon-refresh"></i>
                                    </button>
                                </div>
                                <div class="layui-col-md6 search-form">
                                    <div class="layui-form layui-form-pane search">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">搜索</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="keywords" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                                            </div>
                                            <button class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary search-submit">
                                                <i class="layui-icon layui-icon-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div id="list-table" lay-filter="list-table"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block} {block name="my_js"}
<script type="text/html" id="avatar">
    <img class="table-img" lay-event="tableImg" style="height: 100%;" src="{{ d.avatar }}">
</script>
<script type="text/html" id="menu">
    <a class="layui-btn layui-btn-xs layui-bg-gray" admin-event="formLayer" data-href="/admin/user/admin/edit/{{d.id}}.html" data-title="{{d.user_login}}-管理员编辑"  style="{{ d.id==1 ? 'display:none;' : '' }}" >编辑</a>
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="ON|OFF" lay-filter="status" {{ d.status==1 ? 'checked' : '' }} {{ d.id==1 ? 'disabled' : '' }}>
</script>
<script>
    layui.use(['element', 'admin', 'table', 'form'], function() {
        var table = layui.table,
            admin = layui.admin,
            form = layui.form,
            $ = layui.$;
        var list_table = admin.table(table, 'list-table', 'admin/user/admin', {
            page: true,
            cols: [
                [{
                    field: 'id',
                    title: 'ID',
                    width: 50
                }, {
                    templet: '#avatar',
                    title: '头像',
                    width: 60
                }, {
                    field: 'user_login',
                    title: '登录名',
                    minWidth: 90
                }, {
                    field: 'user_nickname',
                    title: '昵称',
                    minWidth: 90
                }, {
                    field: 'mobile',
                    title: '手机号',
                    minWidth: 130
                }, {
                    field: 'user_email',
                    title: '邮箱',
                    minWidth: 150
                }, {
                    field: 'create_time',
                    title: '创建时间',
                    minWidth: 170
                }, {
                    field: 'status',
                    title: '状态',
                    templet: '#status',
                    width: 100
                }, {
                    fixed: 'right',
                    align: 'center',
                    templet: '#menu',
                    width: 70
                }]
            ]
        });
        form.on('switch(status)', function(obj) {
            admin.ajax('admin/user/toggle/' + this.value, '', function(data) {
                if (data.code == 1001) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg);
                }
            }, '', 'get');
        });
        $('#layui-icon-refresh').click(function() {
            list_table.reload();
        });
        admin.enter(function() {
            $('.search-submit').click();
        });
        $('.search-submit').click(function() {
            var keyword = $("input[name='keywords']").val();
            list_table.reload({
                where: {
                    keyword: keyword
                }
            });
        });
        table.on('tool(list-table)', function(obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            if (layEvent === 'tableImg') {
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    area: ['auto'],
                    skin: 'layui-layer-nobg',
                    shadeClose: true,
                    content: tr.children('td[data-field="1"]').children('.layui-table-cell').html()
                });
            }
        });
    });
</script>
{/block}